const key = "hxzx";
export default {
  /**
   * @description: 加密
   * @param {string} data 内容
   * @return {string}
   */
  encrypt(data: string): string {
    if (!data) return "";
    data = [key, data].join("");
    let result = "";
    for (let i = 0; i < data.length; i++) {
      result += String.fromCharCode(
        data.charCodeAt(i) ^ key.charCodeAt(i % key.length)
      );
    }
    return result;
  },
  /**
   * @description: 解密
   * @param {string} data 内容
   * @return {string}
   */
  decrypt(data: string): string {
    if (!data) return "";
    let result = "";
    for (let i = 0; i < data.length; i++) {
      result += String.fromCharCode(
        data.charCodeAt(i) ^ key.charCodeAt(i % key.length)
      );
    }
    return result.replace(key, "");
  },
};
